<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //数组[]中提取值并赋值给某个元素
        //1赋值给x，2赋值给y
        let [x, y] = [1, 2]
        console.log("x:", x, "y:", y)

        //30赋值给c(,相当于占位符)
        let [, , c] = [10, 20, 30]
        console.log(c)

        //扩展运算符：[…B]相当于把B变成数组，包含每一个元素，(把2.3.4.5.6赋值给B)
        let [A, ...B] = [1, 2, 3, 4, 5, 6]
        console.log(B)

        //默认值
        let [a, b = 200] = [100]
        console.log("a:", a, "b:", b)

        //两数交换(不加分号会报错)
        let x1 = 10
        let y1 = 20;
        [x1, y1] = [y1, x1]
        console.log("x1:", x1, "y1:", y1)

        //对象解构：let{}=perosn
        let person = {
            name: "dengrui",
            age: 18,
            web: "dengruicode.com"
        }
        let { name } = person
        console.log("name", name)
        //重命名
        let { name: username, age, web } = person
        console.log("name", username, "age", age, "web", web)
    </script>
</body>

</html>